<template>
  <div>
    <!-- 使用isAdd 展示添加还是编辑 -->
    <el-dialog
      title="会员编辑"
      :visible.sync="info.isshow"
      @closed="closed"
    
    >
      {{form}}
      <el-form :model="form">
        <!-- 2.绑定数据 -->

        <el-form-item label="手机号" label-width="120px">
          <el-input v-model="form.phone" ></el-input>
        </el-form-item>
        <el-form-item label="昵称" label-width="120px">
          <el-input v-model="form.nickname" ></el-input>
        </el-form-item>
        <el-form-item label="密码" label-width="120px">
          <el-input v-model="form.password" ></el-input>
        </el-form-item>
        <el-form-item label="提示" label-width="120px" v-if="!info.isAdd">
        留空则不修改
        </el-form-item>

        <el-form-item label="状态" label-width="120px">
          <el-switch v-model="form.status" :active-value="1" :inactive-value="2"></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        
        <el-button type="primary"  @click="update">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>

import {
  reqmemberlist,
  reqmenuinfo,
  reqmenuedit,
  reqmemberinfo,
  reqmemberedit,
} from "../../../request/api";
import { errorAlert, successAlert } from "../../../utils/alert";
import path from "path";
import { mapGetters, mapActions } from "vuex";
export default {
  components: {},
  props: ["info"],
  data() {
    return {
      // 1.初始化数据
      form: {
        uid:"",
        nickname:"",
        phone:"",
        password:"",
        status:"2"
      }, 
    };
   
  },
  computed: {
    ...mapGetters({  
    }),
  },
  mounted() {
    // this.reqList()
  },
  methods: {
    ...mapActions({
      reqList: "vip/reqList",
    }),

    //取消
    cancel() {
      this.info.isshow = false;
    },
    //弹框关闭
    closed() {
      if (!this.info.isAdd) {
        this.empty();
      }
    },
    //重置form
    empty() {
      this.form = {
         uid:"",
        nickname:"",
        phone:"",
        password:"",
        status:"2"
      };
      
    },
    //验空的函数
    // checkEmpty() {
    //   return new Promise((resolve, reject) => {
    //     if (this.form.first_cateid == "") {
    //       errorAlert("一级分类不能为空");
    //       return;
    //     }
    //     if (this.form.second_cateid == "") {
    //       errorAlert("二级分类不能为空");
    //       return;
    //     }
    //     if (this.form.goodsname == "") {
    //       errorAlert("商品名称不能为空");
    //       return;
    //     }
    //     if (this.form.price == "") {
    //       errorAlert("价格不能为空");
    //       return;
    //     }
    //     // if (this.form.market_price == "") {
    //     //   errorAlert("市场价格不能为空");
    //     //   return;
    //     // }
    //     if (!this.form.img) {
    //       errorAlert("图片不能为空");
    //       return;
    //     }
    //     if (this.form.specsid == "") {
    //       errorAlert("规格不能为空");
    //       return;
    //     }
    //     if (this.form.specsattr.length == 0) {
    //       errorAlert("规格属性不能为空");
    //       return;
    //     }
    //     if (this.editor.txt.html() === "") {
    //       errorAlert("描述不能空");
    //       return;
    //     }
    //     resolve();
    //   });
    // },
    
    
    //获取一条数据
    getOne(uid) {
      reqmemberinfo({ uid: uid }).then((res) => {
        if (res.data.code == 200) {
          this.form = res.data.list;
          //（1）补id
          // this.form.id = id;
           //密码清空
         this.form.password=""
        }
      });
    },
    //修改
    update() {
      // this.checkEmpty().then(() => {
      // });
       reqmemberedit({
          ...this.form
        }).then((res) => {
          if (res.data.code == 200) {
            // （1）弹成功
            successAlert(res.data.msg);
            // (2)弹框消失
            this.cancel();
            // (3)清空数据
            this.empty();
            // (4)刷新列表
           this.reqList()
          }
        });
    },
  },
};
</script>
<style lang="less" scoped>
@import "../../../less/index.less";
.my-upload {
  width: 100px;
  height: 100px;
  border: 1px dashed @header-color;
  position: relative;
}
.my-plus {
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 100px;
  color: @primary;
}
.my-img {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
}
.my-upload input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}

// /deep/.avatar-uploader .el-upload {
//     border: 1px dashed #d9d9d9;
//     border-radius: 6px;
//     cursor: pointer;
//     position: relative;
//     overflow: hidden;
//   }
//   .avatar-uploader .el-upload:hover {
//     border-color: #dddddd;
//   }
//   .avatar-uploader-icon {
//     font-size: 28px;
//     color: #8c939d;
//     width: 178px;
//     height: 178px;
//     line-height: 178px;
//     text-align: center;
//   }
//   .avatar {
//     width: 178px;
//     height: 178px;
//     display: block;
//   }
</style>